package com.chang.product.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author: changzhenxi
 * @date: 2024年11月25日 11:03
 * @Version: 1.0
 * @description: 线程池配置 这里使用了读取配置文件的类作为参数注入到需要的线程池配置中
 */
@Configuration
public class MyThreadConfig {
    @Bean
    public ThreadPoolExecutor MyThreadConfig(ThreadPoolProperties threadConfig) {
        return new ThreadPoolExecutor(threadConfig.getCoreSize(),
                threadConfig.getMaxSize(),
                threadConfig.getKeepAliveTime(),
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<Runnable>(100000),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
    }
}
